package com.igeek.collateral.mapper;

import com.igeek.collateral.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-07-17
 */
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("select m1.path 'path1', m1.name 'name1',m2.path 'path2' " +
            ",m2.name 'name2',m2.component,meta.title,meta.icon " +
            "from menu m1 join menu m2 on m2.parentMenuId=m1.id ,meta " +
            "where m2.meta_id = meta.id and m1.path=#{path}" +
            " order by m2.priority ")
    List<Map<String, Object>> selectMenuList(String path);


    @Select("select m1.*,m2.id,m2.title,m2.icon \n" +
            "from menu m1 ,meta m2\n" +
            "where m1.meta_id=m2.id and m1.level=1")
    List<Map<String, Object>> selectFirst();

    @Select("select m1.id 'id1',m1.meta_id 'meta_id1', m1.path 'path1', m1.name 'name1' ,m1.priority 'priority1',m1.level 'level1',m1.description 'description1'" +
            ",m2.id 'id2',m2.path 'path2',m2.name 'name2',m2.component, m2.priority 'priority2',m2.level 'level2',m2.description 'description2',m2.parentMenuId 'parentMenuId2'," +
            "meta.id 'meta_id',meta.title,meta.icon " +
            "from menu m1 join menu m2 on m2.parentMenuId=m1.id ,meta " +
            "where m2.meta_id = meta.id and m1.path=#{path}" +
            " order by m2.priority ")
    List<Map<String, Object>> selectMenuList1(String path);
}
